home *** CD-ROM | disk | FTP | other *** search
Text File | 1986-11-19 | 5.4 KB | 228 lines | [TEXT/PJMM] |
- UNIT ScrollStuff;
-
- INTERFACE
-
- USES
- ROM85, EditorGlobals;
-
- PROCEDURE AdjustScrollBar (HandleIndex : integer);
- PROCEDURE ScrollChar (HandleIndex : integer;
- charPos : integer;
- toBottom : boolean);
- PROCEDURE CheckInsertion (HandleIndex : integer);
- PROCEDURE doScrollers (HandleIndex : integer;
- scrollBar : ControlHandle;
- part : integer;
- localMouse : point);
- FUNCTION AutoScroll : boolean;
-
- IMPLEMENTATION
-
- FUNCTION Sign (Longvar : Longint) : integer;
- BEGIN
- IF Longvar >= 0 THEN
- sign := 1
- ELSE IF Longvar < 0 THEN
- sign := -1;
- END;
-
- FUNCTION LinesInText (HandleIndex : integer) : integer;
- { Fix text edit bug for cr at end of text }
- VAR
- i : integer;
- lines : integer;
- texthandle : CharsHandle;
- BEGIN
- i := HandleIndex;
- WITH myText[i]^^ DO
- BEGIN
- lines := nLines;
- texthandle := CharsHandle(hText);
- IF teLength > 0 THEN
- IF texthandle^^[teLength - 1] = CR THEN
- lines := lines + 1;
- LinesInText := lines
- END
- END;
-
- PROCEDURE MoveText (HandleIndex : integer);
- VAR
- ViewTop, DestTop : LongInt;
- scrollvalue : LongInt;
- height : integer;
- i, j : integer;
- scrolldiff : longInt;
- oldScroll : longInt;
- newScroll : longInt;
- BEGIN
- i := HandleIndex;
- ViewTop := myText[i]^^.ViewRect.top;
- DestTop := myText[i]^^.DestRect.top;
- oldScroll := LongInt(ViewTop - DestTop);
- scrollvalue := GetCtlValue(myVControls[i]);
- height := myText[i]^^.lineHeight;
- newScroll := LongInt(scrollvalue * Height);
- scrolldiff := LongInt(oldscroll - newscroll);
- IF abs(scrolldiff) > 32000 THEN
- BEGIN
- TEScroll(0, sign(scrolldiff) * 32000, myText[i]);
- sysbeep(5); {overflow destRect! Text Edit Limitation!}
- END
- ELSE
- BEGIN
- IF (scrolldiff <> 0) THEN
- TEScroll(0, scrolldiff, myText[i]); {vertical - see bug TN#22}
- END;
- END;
-
- PROCEDURE scroll_up (theControl : controlHandle;
- partCode : integer);
- VAR
- newValue : integer;
- BEGIN
- newValue := GetCtlValue(theControl) - 1;
- SetCtlValue(theControl, newValue);
- moveText(currentWindow);
- END;
-
- PROCEDURE scroll_down (theControl : controlHandle;
- partCode : integer);
- VAR
- newValue : integer;
- BEGIN
- newValue := GetCtlValue(theControl) + 1;
- SetCtlValue(theControl, newValue);
- moveText(currentWindow);
- END;
-
- PROCEDURE page_scroll (part : integer;
- scrollBar : ControlHandle;
- direction : integer);
- VAR
- newValue : integer;
- page : integer;
- BEGIN
- WITH myText[currentWindow]^^, viewRect DO
- page := direction * ((bottom - top) DIV lineHeight - 1);
- newValue := GetCtlValue(scrollBar) + page;
- SetCtlValue(scrollBar, newValue);
- moveText(currentWindow);
- END;
-
- PROCEDURE AdjustScrollBar; {(HandleIndex:integer)}
- VAR
- WindowLInes : integer;
- i : integer;
- currentLines : integer;
- BEGIN
- i := HandleIndex;
- WITH myText[i]^^ DO
- WindowLines := ((ViewRect.bottom - ViewRect.top) DIV lineHeight);
- currentLines := LinesInText(i);
- IF currentLines >= WindowLines THEN
- SetCtlMax(myVControls[i], currentLines - WindowLines)
- ELSE
- SetCtlMax(myVControls[i], 0)
- END;
-
- PROCEDURE ScrollChar; {(HandleIndex : integer;}
- {charPos : integer;}
- {toBottom : boolean);}
- VAR
- i : integer;
- theLine : integer;
- WindowLines : integer;
- BEGIN
- i := HandleIndex;
- theLine := 0;
- WITH myText[i]^^ DO
- WHILE lineStarts[theLine + 1] <= CharPos DO
- theLine := theLine + 1;
- IF toBottom THEN
- BEGIN
- WITH myText[i]^^ DO
- windowLines := (viewRect.bottom - viewRect.top) DIV lineheight;
- theLine := theLine - (windowLines - 1);
- END;
- setCtlValue(myVControls[i], theLine);
- MoveText(i);
- END;
-
- PROCEDURE checkInsertion; {(HandleIndex : integer)}
- VAR
- i : integer;
- topline : integer;
- bottomline : integer;
- WindowLines : integer;
-
- BEGIN
- i := HandleIndex;
- WITH myText[i]^^ DO
- WindowLines := (ViewRect.bottom - ViewRect.top) DIV lineHeight;
- topline := GetCtlValue(myVControls[i]);
- bottomline := topLine + WindowLines;
- WITH myText[i]^^ DO
- IF GetCtlMax(myVControls[i]) = 0 THEN
- MoveText(i)
- ELSE IF selEnd < lineStarts[topLine] THEN
- ScrollChar(i, selStart, False)
- ELSE IF selStart >= lineStarts[bottomLine] THEN
- ScrollChar(i, selEnd, true);
- END;
-
- PROCEDURE doScrollers; {HandleIndex:integer}
- {(scrollBar : ControlHandle}
- {part : integer}
- {localMouse : point)}
- VAR
- result : integer;
- i : integer;
- BEGIN
- i := HandleIndex;
- CASE part OF
- inUpButton :
- result := TrackControl(scrollbar, localMouse, @scroll_up);
- inDownButton :
- result := TrackControl(scrollbar, localMouse, @scroll_down);
- inPageUp :
- page_scroll(part, scrollBar, -1);
- inPageDown :
- page_scroll(part, scrollBar, 1);
- inThumb :
- BEGIN
- result := TrackControl(scrollBar, localMouse, NIL);
- moveText(i);
- END;
- OTHERWISE
- BEGIN
- END;
- END; {of case}
- END; {of proc}
-
- FUNCTION AutoScroll; {:boolean;}
- VAR
- result : boolean;
- oldClip : RgnHandle;
- mouseLoc : point;
- TextRect : rect;
- i : integer;
- control : controlHandle;
- BEGIN
- i := currentWindow;
- result := true;
- oldClip := NewRgn;
- GetClip(oldClip);
- ClipRect(myWindows[i]^.portRect);
- GetMouse(mouseLoc);
- TextRect := myText[i]^^.viewRect;
- Control := myVControls[i];
- IF mouseLoc.v < TextRect.top THEN
- Scroll_Up(Control, InUpButton)
- ELSE IF mouseLoc.v > TextRect.bottom THEN
- Scroll_Down(Control, InDownButton);
- SetClip(oldClip);
- DisposeRgn(oldClip);
- AutoScroll := result;
- END;
-
- END. {of unit}